#include <Arduino.h>

#define d4 27
#define d6 33
void init_LED()
{
  pinMode(d4,OUTPUT);
  pinMode(d6,OUTPUT);
}

void init_UART()
{
  Serial.begin(115200);
}

void serial_control_LED()
{
  if(Serial.available() > 0)
  {
    unsigned char cmd = 0;
    cmd = Serial.read();
    switch(cmd)
    {
        case 0xA1: 
          digitalWrite(d4,HIGH);
          Serial.println("D4 is opened!");//输出字符串带回车换行
        break;
        case 0xA2: 
          digitalWrite(d6,HIGH);
          Serial.println("D6 is opened!");
        break;
        case 0xB1: 
          digitalWrite(d4,LOW);
          Serial.println("D4 is closed!");
          break;
        case 0xB2: 
          digitalWrite(d4,LOW);
          Serial.println("D4 is closed!");
            break;
        
        default :
          Serial.println("ERROR!!!");
        break;
    }

  }

}

void setup() {
  init_LED();
  init_UART();
}

void loop() {
  serial_control_LED();

}
